package aom.ju.ss.view.dialog

import android.app.Activity
import androidx.core.content.ContextCompat
import aom.ju.ss.R
import aom.ju.ss.databinding.ChoosePostageTemplateBinding

/**
 * 选择 运费模板
 */
class ChoosePostageTemplate(activity: Activity?, var callBack: ChoosePostageTemplateInterface) :
    BaseDialog(activity) {
    override fun isBottom(): Boolean {
        return true
    }

    init {
        setWidth(-1)
    }

    lateinit var binding: ChoosePostageTemplateBinding

    override fun init() {
        binding = vBinding as ChoosePostageTemplateBinding

        val drawable = ContextCompat.getDrawable(activity, R.drawable.ic_cb_xuanzhong)
        drawable?.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)

        binding.quanguo.setOnClickListener {
            initBt()
            binding.quanguo.setCompoundDrawables(null, null, drawable, null)
            callBack.ok(0)
            dis()
        }

        binding.ziti.setOnClickListener {
            callBack.ok(1)
            initBt()
            binding.ziti.setCompoundDrawables(null, null, drawable, null)
            dis()
        }

        binding.maijia.setOnClickListener {
            callBack.ok(2)
            initBt()
            binding.maijia.setCompoundDrawables(null, null, drawable, null)
            dis()
        }
        binding.gb.setOnClickListener { dis() }

    }

    private fun initBt() {
        val drawable = ContextCompat.getDrawable(activity, R.drawable.unselector)
        drawable?.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
        binding.quanguo.setCompoundDrawables(null, null, drawable, null)
        binding.ziti.setCompoundDrawables(null, null, drawable, null)
        binding.maijia.setCompoundDrawables(null, null, drawable, null)
    }

    override fun getLay(): Int {
        return R.layout.choose_postage_template
    }
}

interface ChoosePostageTemplateInterface {
    fun ok(type: Int)
}